<script src="../../resources/js-test.js"></script>
<style>
    #pusher {
        width: 1000px;
        height: 1000px;
        outline: 1px solid black;
    }
</style>
<div id="console"></div>
<div id="testArea">
    <div id="pusher">This box is here to create scrollbars.</div>
</div>
<script>
    var event;

    function sendClick()
    {
        if (window.eventSender) {
            eventSender.mouseMoveTo(100, 100);
            eventSender.mouseDown();
            eventSender.mouseUp();
        }
    }

    function zoomPageIn()
    {
        if (window.testRunner) {
            testRunner.zoomPageIn();
        }
    }

    function zoomPageOut()
    {
        if (window.testRunner) {
            testRunner.zoomPageOut();
        }
    }

    function scrollPage(x, y)
    {
        window.scrollTo(x, y);
    }

    if (window.testRunner) {
        testRunner.dumpAsText();
        testRunner.waitUntilDone();
    }

    // Default.
    function base(e)
    {
        event = e;
        debug("Base");
        shouldBe("event.clientX", "100");
        shouldBe("event.clientY", "100");
        shouldBe("event.pageX", "100");
        shouldBe("event.pageY", "100");
    }
    window.addEventListener("click", base, false);
    sendClick();
    window.removeEventListener("click", base, false);

    // Just zoomed.
    function justZoomed(e)
    {
        event = e;
        debug("\nJust zoomed");
        shouldBe("event.clientX", "83");
        shouldBe("event.clientY", "83");
        shouldBe("event.pageX", "83");
        shouldBe("event.pageX", "83");
    }
    window.addEventListener("click", justZoomed, false);
    zoomPageIn();
    sendClick();
    zoomPageOut();
    window.removeEventListener("click", justZoomed, false);

    // Just scrolled.
    function justScrolled(e)
    {
        event = e;
        debug("\nJust scrolled");
        shouldBe("event.clientX", "100");
        shouldBe("event.clientY", "100");
        shouldBe("event.pageX", "150");
        shouldBe("event.pageY", "150");
    }
    window.addEventListener("click", justScrolled, false);
    scrollPage(50, 50);
    sendClick();
    scrollPage(0, 0);
    window.removeEventListener("click", justScrolled, false);

    // Zoomed and scrolled.
    function zoomedAndScrolled(e)
    {
        event = e;
        debug("\nZoomed and scrolled");
        shouldBe("event.clientX", "83");
        shouldBe("event.clientY", "83");
        shouldBe("event.pageX", "133");
        shouldBe("event.pageY", "133");
    }
    window.addEventListener("click", zoomedAndScrolled, false);
    zoomPageIn();
    scrollPage(50, 50);
    sendClick();
    zoomPageOut();
    scrollPage(0, 0);
    window.removeEventListener("click", zoomedAndScrolled, false);

    // RTL.
    function rtlAndScrolled(e)
    {
        event = e;
        debug("\nRTL and scrolled");
        shouldBe("event.clientX", "100");
        shouldBe("event.clientY", "100");
        shouldBe("event.pageX", "50");
        shouldBe("event.pageY", "150");
    }
    window.addEventListener("click", rtlAndScrolled, false);
    document.documentElement.dir = "rtl";
    scrollPage(-50, 50);
    sendClick();
    scrollPage(0, 0);
    document.documentElement.dir = "";
    window.removeEventListener("click", rtlAndScrolled, false);

    if (window.testRunner) {
        var area = document.getElementById('testArea');
        area.parentNode.removeChild(area);

        testRunner.notifyDone();
    }
</script>
